/**
 * 
 */
package com.et114.core.action;

//import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

//import com.et114.core.common.AppContext;
import com.et114.core.utility.ThreadSynchronizer;

/*
 * @author guanhw
 */
abstract public class AbstractExportAction extends BaseAction {
	protected Log	logger	= LogFactory.getLog ( this.getClass ( ) );
	
	protected void setResponseHeaders ( HttpServletResponse response  ) {
		/*
        String charSet = AppContext.getFrameWorkPropertiesBean().getCharSet() ;
        try {
            exportFileName = new String( exportFileName.getBytes( charSet ) , "ISO-8859-1" ) ;
		} catch ( UnsupportedEncodingException e ) {
			String errorMessage = "Unsupported response.getCharacterEncoding() [" + charSet + "].";
            logger.error("EccnAbstractExportFilter.setResponseHeaders() - " + errorMessage);
		}
		*/
		response.setHeader ( "Cache-Control" , "must-revalidate, post-check=0, pre-check=0" );
		response.setHeader ( "Pragma" , "public" );
		response.setDateHeader ( "Expires" , ( System.currentTimeMillis ( ) + 1000 ) );
	}
	
	

	
	public final ActionForward toExecute ( ActionMapping mapping ,
			ActionForm form , HttpServletRequest request ,
			HttpServletResponse response ) throws Exception {
		setResponseHeaders ( response );
		ThreadSynchronizer.threadEnter ( );
		ActionForward af = null ; 
		try {
			af = exporter ( mapping , form , request , response );
		}
		finally {
			ThreadSynchronizer.threadExit ( );
		}
		return af;
	}
	
	abstract protected ActionForward exporter(  ActionMapping mapping ,
			ActionForm form , HttpServletRequest request , HttpServletResponse response )  throws Exception  ;
	
}
